<<<<<<< HEAD NYC Restaurant Inspection ======= >>>>>>> f4bc21f27896876a5370a230b87e49c20303f6ff NYC Restaurant Inspection <<<<<<< HEAD

Column

Number of Critical and Non-Critical Violations Across Time

library(p8105.datasets)
library(tidyverse)
## -- Attaching packages --------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.0.0     v purrr   0.2.5
## v tibble  1.4.2     v dplyr   0.7.6
## v tidyr   0.8.1     v stringr 1.3.1
## v readr   1.1.1     v forcats 0.3.0
## -- Conflicts ------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
inspection_data = rest_inspec %>%
  select(boro, score, critical_flag, cuisine_description, grade, inspection_date) %>%
  mutate(inspection_date = as.Date(inspection_date)) %>%
  mutate(cuisine_description = recode(cuisine_description, "Café/Coffee/Tea" = "Cafe", "Latin (Cuban, Dominican, Puerto Rican, South & Central American)" = "Latin"))

library(lubridate)
## 
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
## 
##     date
inspection_data %>%
  filter(inspection_date > "2014-01-01") %>%
  filter(critical_flag != "Not Applicable") %>%
  group_by(critical_flag, inspection_date = floor_date(inspection_date, "month")) %>%
  summarize(n = n()) %>%
  plot_ly(x = ~inspection_date, y = ~n, color = ~critical_flag, type = "scatter", mode = "lines") 
## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

## Warning in RColorBrewer::brewer.pal(N, "Set2"): minimal value for n is 3, returning requested palette with 3 different levels

Column

Restaurant Grades by Borough

inspection_data %>%
  filter(grade == "C" | grade == "B" | grade == "A") %>%
  filter(!boro == "Missing") %>%
  group_by(boro, grade) %>%
  summarize(n = n()) %>%
  plot_ly(x = ~boro, y = ~n, color = ~grade, type = "bar") %>% 
  layout(barmode = "stack")

Distribution of Violation Scores by Restaurant Type

top_cuisine_type = 
  inspection_data %>%
  count(cuisine_description, sort = TRUE) %>% 
  top_n(8)
## Selecting by n
inner_join(inspection_data, top_cuisine_type, by = "cuisine_description") %>% 
  plot_ly(y = ~score, color = ~cuisine_description, type = "box",
          colors = "Set2")
## Warning: Ignoring 12697 observations

Column

Number of Critical and Non-Critical Violations Across Time

Column

Restaurant Grades by Borough

Distribution of Violation Scores by Restaurant Type

======= >>>>>>> f4bc21f27896876a5370a230b87e49c20303f6ff